package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.db.conn;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class assesss_Add extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public assesss_Add() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	//添加评价信息
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		PrintWriter out = response.getWriter();

		conn cn = new conn();
	
	    String f=request.getParameter("f");

        String rno=request.getParameter("id");
        String rid=request.getParameter("rid");
        String pj=request.getParameter("sc");
        String pjnr=request.getParameter("memo");
        String mid=request.getParameter("mid");
		
		
        String sql="insert into assesss(rno,rid,pj,pjnr,mid,atime)" +
				" values('"+rno+"',"+rid+","+pj+",'"+pjnr+"',"+mid+",now())";
       
		
		


		
		int i=cn.update(sql);


		String ss=request.getParameter("photo");
		ResultSet rs=cn.query("select aid from assesss order by aid desc limit 0,1");
		try {
			if(rs.next())
			{
				String hid=rs.getString("aid");
				for (String s:ss.split(","))
				{
					cn.update("insert into photo(aid, addr) " +
							"values("+hid+",'"+s+"')");
				}
			}
		} catch (SQLException throwables) {
			throwables.printStackTrace();
		}


		JSONArray jsonarray = new JSONArray();
		JSONObject jsonobj = new JSONObject();
		jsonobj.put("jieguo", 1);
		jsonarray.add(jsonobj);
		out = response.getWriter();
		out.println(jsonarray);



	
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

